package com.newtouch.bxzs.database.synchronize.batch.job;

import com.newtouch.bxzs.database.synchronize.batch.step.*;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 同步类Job
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/2/25 10:54</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class SynchronizeJob {

    @Autowired
    private JobBuilderFactory jobBuilderFactory;

    @Autowired
    private AchievementStep achievementStep;

    @Autowired
    private CustomerStep customerStep;

    @Autowired
    private IncomeStep incomeStep;

    @Autowired
    private OrganizationStep organizationStep;

    @Autowired
    private ProductStep productStep;

    @Autowired
    private SystemUserStep systemUserStep;

    /**
     * 同步业绩信息
     * @return Job
     */
    public Job syncchronizeAchievementJob(){
        return jobBuilderFactory.get("syncchronizeAchievementJob")
                .incrementer(new RunIdIncrementer())
                .start(achievementStep.synchronizeAchievement())
                .next(achievementStep.synchronizeAchievementPolicy())
                .build();
    }

    /**
     * 同步客户数据
     * @return job
     */
    public Job synchronizeCustomerJob(){
        return jobBuilderFactory.get("synchronizeCustomerJob")
                .incrementer(new RunIdIncrementer())
                .start(customerStep.synchronizeCustomerStep())
                .build();
    }

    /**
     * 同步收入数据
     * @return Job
     */
    public Job synchronizeIncomeJob(){
        return jobBuilderFactory.get("synchronizeIncomeJob")
                .incrementer(new RunIdIncrementer())
                .start(incomeStep.synchronizeIncomeStep())
                .next(incomeStep.synchronizeIncomeDetailStep())
                .next(incomeStep.synchronizeIncomeEstimateStep())
                .next(incomeStep.synchronizeIncomeEstimateDetailStep())
                .build();
    }

    /**
     * 同步机构数据
     * @return Job
     */
    public Job synchronizeOrganJob(){
        return jobBuilderFactory.get("synchronizeOrganJob")
                .incrementer(new RunIdIncrementer())
                .start(organizationStep.bankOrganStep())
                .next(organizationStep.insuranceOrganStep())
                .build();
    }

    /**
     * 同步产品信息
     * @return Job
     */
    public Job syncchronizeProductJob(){
        return jobBuilderFactory.get("syncchronizeProductJob")
                .incrementer(new RunIdIncrementer())
                .start(productStep.synProductStep())
                .build();
    }

    /**
     * 同步用户信息
     * @return Job
     */
    public Job synchronizeUserJob(){
        return jobBuilderFactory.get("synchronizeUserJob")
                .incrementer(new RunIdIncrementer())
                .start(systemUserStep.bankUserStep())
                .next(systemUserStep.insuranceUser())
                .build();
    }
}
